package com.byxy.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;

import com.byxy.entity.Reply;

public interface ReplyDao {
	@Select("select * from reply")
	@Results({ @Result(column = "reply_id", property = "replyId", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "reply_content", property = "replyContent", jdbcType = JdbcType.VARCHAR),
			@Result(column = "reply_publishTime", property = "replyPublishTime", jdbcType = JdbcType.DATE),
			@Result(column = "reply_modifyTime", property = "replyStatus", jdbcType = JdbcType.DATE),
			@Result(column = "reply_status", property = "replyStatus", jdbcType = JdbcType.INTEGER),
			@Result(column = "user_id", property = "replyStatus", jdbcType = JdbcType.INTEGER),
			@Result(column = "tip_id", property = "replyStatus", jdbcType = JdbcType.INTEGER) })
	List<Reply> findAll();

	@Select("select * from reply where reply_id=#{replyId}")
	@Results({ @Result(column = "reply_id", property = "replyId", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "reply_content", property = "replyContent", jdbcType = JdbcType.VARCHAR),
			@Result(column = "reply_publishTime", property = "replyPublishTime", jdbcType = JdbcType.DATE),
			@Result(column = "reply_modifyTime", property = "replyStatus", jdbcType = JdbcType.DATE),
			@Result(column = "reply_status", property = "replyStatus", jdbcType = JdbcType.INTEGER),
			@Result(column = "user_id", property = "user.userId", jdbcType = JdbcType.INTEGER),
			@Result(column = "tip_id", property = "tip.tipId", jdbcType = JdbcType.INTEGER) })
	Reply get(Integer replyId);

	@Insert("insert into reply(tip_id,reply_content,user_id) values(#{tipId},#{replyContent},#{userId})")
	public void add(@Param("tipId") Integer tipId, @Param("replyContent") String replyContent,
			@Param("userId") Integer userId);

	@Delete("delete from reply where tip_id=#{tipId}")
	void delete(@Param("tipId") Integer tipId);

}
